package com.by.service.sys.impl;

import com.by.entity.sys.ModifyUser;
import com.by.entity.sys.User;
import com.by.common.bean.PageBean;
import com.by.dao.sys.UserDao;
import com.by.service.sys.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    public int save(User user) {
        //验证用户名是否存在
        int rs=userDao.queryUser(user.getAccount());
        if(rs>0)
            return 2; //保存失败
        return userDao.save(user);
    }

    @Override
    public int update(User user) {
        return userDao.update(user);
    }

    @Override
    public PageBean query(Map map) {
        if(!map.containsKey("page")){
            map.put("page",1);//如果没有page参数 默认为1
        }
        if(!map.containsKey("pageSize")){
            map.put("pageSize",10);
        }
        List list=userDao.query(map);
        long total=userDao.queryCount(map);
        return new PageBean(Integer.parseInt(map.get("page").toString()),Integer.parseInt(map.get("pageSize").toString()),total,list);
    }


    @Override
    public int delete(String id) {
        return userDao.delete(id);
    }

    @Override
    public int checkuser(String username) {
        return userDao.queryUser(username);
    }


    @Override
    public User queryUser(String account) {
        return userDao.queryUserByAccount(account);
    }

    @Override
    public User queryUserById(String id) {
        return userDao.queryUserById(id);
    }

    @Override
    public int updatePwd(ModifyUser user) {
        return userDao.updatePwd(user);
    }
}
